﻿@model Orchard.ContentPermissions.ViewModels.ContentPermissionsPartViewModel

@{
    Style.Include("orchard-contentpermissions-admin.css");
}

<div>
    @Html.EditorFor(m => m.Enabled) 
    <label class="forcheckbox" for="@Html.FieldIdFor(m => m.Enabled)">@T("Enable Content Item access control")</label>
    <span class="hint">@T("Check to define custom permissions for this content item.")</span>
</div>

<div data-controllerid="@Html.FieldIdFor(m => m.Enabled)">
            
<fieldset>
    <div>
        <table class="content-permissions">
            <tr>
                <th class="role"><h3>@T("Role")</h3></th>
                <th><h3>@T("View this item")</h3></th>
                <th><h3>@T("Edit this item")</h3></th>
                <th><h3>@T("Publish this item")</h3></th>
                <th><h3>@T("Delete this item")</h3></th>
            </tr>
            
            @foreach (var r in Model.AllRoles.Select((x, i) => new { Index = i, Name = x.Role, x.Checked })) {
                var role = r;
                <tr style="@(!role.Checked ? "display:none" : "")">
                    <td class="role">@role.Name</td>
                    <td>
                        <label>
                            <input type="checkbox" disabled="disabled" @if (Model.ViewRoles.Any(x => x.Role == role.Name && x.Default)) { <text>checked="checked"</text> } title="Current value"/>
                            <input type="checkbox" value="true" @if (Model.ViewRoles.Any(x => x.Role == role.Name && x.Checked)) { <text>checked="checked"</text> } name="@Html.FieldNameFor(m => m.ViewRoles[role.Index].Checked)" id="@Html.FieldIdFor(m => m.ViewRoles[role.Index].Checked)" @if (!Model.ViewRoles[role.Index].Enabled) { <text>disabled="disabled"</text> }/>
                        </label>
                        @Html.HiddenFor(m => m.ViewRoles[role.Index].Role)
                    </td>
                    <td>
                        <label>
                            <input type="checkbox" disabled="disabled" @if (Model.PublishRoles.Any(x => x.Role == role.Name && x.Default)) { <text>checked="checked"</text> } title="Current value"/>
                            <input type="checkbox" value="true" @if (Model.PublishRoles.Any(x => x.Role == role.Name && x.Checked)) { <text>checked="checked"</text> } name="@Html.FieldNameFor(m => m.PublishRoles[role.Index].Checked)" id="@Html.FieldIdFor(m => m.PublishRoles[role.Index].Checked)" @if (!Model.PublishRoles[role.Index].Enabled) { <text>disabled="disabled"</text> }/>
                        </label>
                        @Html.HiddenFor(m => m.PublishRoles[role.Index].Role)
                    </td>
                    <td>
                        <label>
                            <input type="checkbox" disabled="disabled" @if (Model.EditRoles.Any(x => x.Role == role.Name && x.Default)) { <text>checked="checked"</text> } title="Current value"/>
                            <input type="checkbox" value="true" @if (Model.EditRoles.Any(x => x.Role == role.Name && x.Checked)) { <text>checked="checked"</text> } name="@Html.FieldNameFor(m => m.EditRoles[role.Index].Checked)" id="@Html.FieldIdFor(m => m.EditRoles[role.Index].Checked)" @if (!Model.EditRoles[role.Index].Enabled) { <text>disabled="disabled"</text> }/>
                        </label>
                        @Html.HiddenFor(m => m.EditRoles[role.Index].Role)
                    </td>
                    <td>
                        <label>
                            <input type="checkbox" disabled="disabled" @if (Model.DeleteRoles.Any(x => x.Role == role.Name && x.Default)) { <text>checked="checked"</text> } title="Current value"/>
                            <input type="checkbox" value="true" @if (Model.DeleteRoles.Any(x => x.Role == role.Name && x.Checked)) { <text>checked="checked"</text> } name="@Html.FieldNameFor(m => m.DeleteRoles[role.Index].Checked)" id="@Html.FieldIdFor(m => m.DeleteRoles[role.Index].Checked)" @if (!Model.DeleteRoles[role.Index].Enabled) { <text>disabled="disabled"</text> }/>
                        </label>
                        @Html.HiddenFor(m => m.DeleteRoles[role.Index].Role)
                    </td>
                </tr>
            }
        </table>
        <table class="content-permissions">
            <tr>
                <th class="role"><h3>@T("Role")</h3></th>
                <th><h3>@T("View own")</h3></th>
                <th><h3>@T("Edit own")</h3></th>
                <th><h3>@T("Publish own")</h3></th>
                <th><h3>@T("Delete own")</h3></th>
            </tr>

            @foreach (var r in Model.AllRoles.Select((x, i) => new { Index = i, Name = x.Role, x.Checked })) {
                var role = r;
                <tr style="@(!role.Checked ? "display:none" : "")">
                    <td class="role">@role.Name</td>
                    <td>
                        <label>
                            <input type="checkbox" disabled="disabled" @if (Model.ViewOwnRoles.Any(x => x.Role == role.Name && x.Default)) { <text>checked="checked"</text> } title="Current value"/>
                            <input type="checkbox" value="true" @if (Model.ViewOwnRoles.Any(x => x.Role == role.Name && x.Checked)) { <text>checked="checked"</text> } name="@Html.FieldNameFor(m => m.ViewOwnRoles[role.Index].Checked)" id="@Html.FieldIdFor(m => m.ViewOwnRoles[role.Index].Checked)" @if (!Model.ViewOwnRoles[role.Index].Enabled) { <text>disabled="disabled"</text> }/>
                        </label>
                        @Html.HiddenFor(m => m.ViewOwnRoles[role.Index].Role)
                    </td>
                    <td>
                        <label>
                            <input type="checkbox" disabled="disabled" @if (Model.PublishOwnRoles.Any(x => x.Role == role.Name && x.Default)) { <text>checked="checked"</text> } title="Current value"/>
                            <input type="checkbox" value="true" @if (Model.PublishOwnRoles.Any(x => x.Role == role.Name && x.Checked)) { <text>checked="checked"</text> } name="@Html.FieldNameFor(m => m.PublishOwnRoles[role.Index].Checked)" id="@Html.FieldIdFor(m => m.PublishOwnRoles[role.Index].Checked)" @if (!Model.PublishOwnRoles[role.Index].Enabled) { <text>disabled="disabled"</text> }/>
                        </label>
                        @Html.HiddenFor(m => m.PublishOwnRoles[role.Index].Role)
                    </td>
                    <td>
                        <label>
                            <input type="checkbox" disabled="disabled" @if (Model.EditOwnRoles.Any(x => x.Role == role.Name && x.Default)) { <text>checked="checked"</text> } title="Current value"/>
                            <input type="checkbox" value="true" @if (Model.EditOwnRoles.Any(x => x.Role == role.Name && x.Checked)) { <text>checked="checked"</text> } name="@Html.FieldNameFor(m => m.EditOwnRoles[role.Index].Checked)" id="@Html.FieldIdFor(m => m.EditOwnRoles[role.Index].Checked)" @if (!Model.EditOwnRoles[role.Index].Enabled) { <text>disabled="disabled"</text> }/>
                        </label>
                        @Html.HiddenFor(m => m.EditOwnRoles[role.Index].Role)
                    </td>
                    <td>
                        <label>
                            <input type="checkbox" disabled="disabled" @if (Model.DeleteOwnRoles.Any(x => x.Role == role.Name && x.Default)) { <text>checked="checked"</text> } title="Current value"/>
                            <input type="checkbox" value="true" @if (Model.DeleteOwnRoles.Any(x => x.Role == role.Name && x.Checked)) { <text>checked="checked"</text> } name="@Html.FieldNameFor(m => m.DeleteOwnRoles[role.Index].Checked)" id="@Html.FieldIdFor(m => m.DeleteOwnRoles[role.Index].Checked)" @if (!Model.DeleteOwnRoles[role.Index].Enabled) { <text>disabled="disabled"</text> }/>
                        </label></td>
                    @Html.HiddenFor(m => m.DeleteOwnRoles[role.Index].Role)
                </tr>
            }
        </table>
    </div>
</fieldset>
</div>
